import java.util.ArrayList;
import java.util.List;

public class ConsecutiveNumbersSum {

    public int consecutiveNumbersSum1(int n) {
        int l = 1;
        int r = 1;
        int sum = l;
        int ans = 0;
        while (l <= r) {
            if (sum < n) {
                ++r;
                sum += r;
            } else {
                if (sum == n) ++ans;
                sum -= l;
                ++l;
            }
        }
        return ans;
    }

    public int consecutiveNumbersSum2(int n) {
        List<Long> list = new ArrayList<>();
        long sum = 0;
        int ans = 0;
        list.add(0L);
        for (int i = 1; i <= n; i++) {
            sum += i;
            list.add(sum);
            if (list.contains(sum - n)) ++ans;
        }
        return ans;
    }

    public int consecutiveNumbersSum(int n) {
        n *= 2;
        int ans = 0;
        for (int i = 1; i * i < n; i++) {
            if (n % i == 0 && (n / i - i) % 2 == 1) ++ans;
        }
        return ans;
    }
}
